package com.lzb.browser.activity;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.FragmentUtils;
import com.lzb.browser.BaseAc;
import com.lzb.browser.R;
import com.lzb.browser.databinding.ActivityHistoryBinding;
import com.lzb.browser.fragment.BookmarkFragment;
import com.lzb.browser.fragment.CollectFragment;
import com.lzb.browser.fragment.RecordFragment;

import java.util.ArrayList;
import java.util.List;

public class HistoryActivity extends BaseAc<ActivityHistoryBinding> implements View.OnClickListener {

    private List<Fragment> mFragmentList;

    @Override
    protected int onCreate() {
        return R.layout.activity_history;
    }

    @Override
    protected void initView() {
        mDataBinding.ivHistoryBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.llCollectUrl.setOnClickListener(this);
        mDataBinding.llBookmark.setOnClickListener(this);
        mDataBinding.llHistory.setOnClickListener(this);

        mFragmentList = new ArrayList<>();
        mFragmentList.add(new CollectFragment());
        mFragmentList.add(new BookmarkFragment());
        mFragmentList.add(new RecordFragment());
        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.flContainer, 0);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.llCollectUrl) {//收藏网址
            clearSelection();
            mDataBinding.ivCollectUrl.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(0, mFragmentList);
        } else if (id == R.id.llBookmark) {//书签
            clearSelection();
            mDataBinding.ivBookmark.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(1, mFragmentList);
        } else if (id == R.id.llHistory) {//历史
            clearSelection();
            mDataBinding.ivHistory.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(2, mFragmentList);
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.ivCollectUrl.setVisibility(View.INVISIBLE);
        mDataBinding.ivBookmark.setVisibility(View.INVISIBLE);
        mDataBinding.ivHistory.setVisibility(View.INVISIBLE);
    }

}